//
// Decompiled by Jadx - 450ms
//
package gc;

import android.text.TextUtils;
import com.google.gson.Gson;
import de.robv.android.xposed.XposedHelpers;
import fn.j;
import fn.x;
import fn.y;
import fo.b;
import fo.c;
import java.lang.reflect.Proxy;
import java.util.HashMap;
import java.util.Map;
import me.plusne.common.Json.JsonHookStatic;
import org.luckypray.dexkit.query.matchers.ClassMatcher;
import org.luckypray.dexkit.query.matchers.MethodMatcher;
import org.luckypray.dexkit.result.ClassData;
import org.luckypray.dexkit.result.MethodData;

public final class ac extends x {
    public static ClassData cp;
    public static MethodData cq;
    public static MethodData cr;
    public static ClassData cs;
    public static MethodData ct;
    public static MethodData cu;
    public static MethodData cv;
    public static MethodData cw;
    public static ClassData cx;
    public static MethodData cy;
    public static MethodData cz;
    public static MethodData da;
    public Object db;

    public static void dc(String str, String str2, String str3, b bVar, Object... objArr) {
        String str4;
        JsonHookStatic jsonHookStatic = y.by;
        if (jsonHookStatic.isLogin() && jsonHookStatic.getUserInfo().getLevel() >= 5) {
            str4 = y.cj("ApiConstants");
        } else {
            str4 = "cn.soulapp.android.lib.common.api.ApiConstants";
        }
        Class ak = j.ak(str4);
        Object staticObjectField = XposedHelpers.getStaticObjectField(ak, "USER");
        if (staticObjectField != null) {
            String e = b.e("CallInterface");
            String e2 = b.e("CallApi");
            if (TextUtils.isEmpty(e) || TextUtils.isEmpty(e2)) {
                if (cz == null) {
                    cz = c.t(MethodMatcher.create().declaredClass(staticObjectField.getClass()).returnType(Object.class).paramCount(1).paramTypes(new Class[]{Class.class}));
                }
                e = cz.getMethodName();
                b.g("CallInterface", e);
                if (da == null) {
                    da = c.t(MethodMatcher.create().declaredClass(staticObjectField.getClass()).returnType("com.walid.rxretrofit.HttpSubscriber").paramCount(2));
                }
                e2 = da.getMethodName();
                b.g("CallApi", e2);
            }
            Object staticObjectField2 = XposedHelpers.getStaticObjectField(ak, str2);
            if (staticObjectField2 != null) {
                Object ab = j.ab(staticObjectField2, e, new Object[]{j.ak(str)});
                if (ab != null) {
                    try {
                        j.ab(staticObjectField2, e2, new Object[]{j.ab(ab, str3, objArr), Proxy.newProxyInstance(jsonHookStatic.getClassLoader(), new Class[]{j.ak("com.walid.rxretrofit.interfaces.IHttpCallback")}, new a(bVar))});
                        return;
                    } catch (NoSuchMethodError e3) {
                        e3.printStackTrace();
                        j.bi(new Object[]{androidx.activity.b.i("没有 ", str3, " 或者方法参数不正确")});
                        return;
                    }
                }
                j.bi(new Object[]{"funApi is Null"});
                return;
            }
            j.bi(new Object[]{"Api is Null"});
        }
    }

    public final void a() {
    }

    public final void dd(String str) {
        de(str, new HashMap(), "GET");
    }

    public final void de(String str, HashMap hashMap, String str2) {
        Object ab;
        Object ab2;
        if (hashMap == null) {
            hashMap = new HashMap();
        }
        Object bl = j.bl(cp.getName(), new Object[0]);
        if (bl == null || (ab = j.ab(bl, cq.getMethodName(), new Object[]{str})) == null) {
            return;
        }
        Object staticObjectField = XposedHelpers.getStaticObjectField(j.ak("retrofit2.converter.gson.GsonRequestBodyConverter"), "MEDIA_TYPE");
        String str3 = str2.equals("JSON") ? "POST" : str2;
        if (str3.equals("POST") || str3.equals("PUT")) {
            if (str2.equals("JSON")) {
                Object ad = j.ad(j.ak(cs.getName()), ct.getMethodName(), new Object[]{staticObjectField, new Gson().toJson(hashMap)});
                if (ad == null || (ab = j.ab(ab, cr.getMethodName(), new Object[]{str3, ad})) == null) {
                    return;
                }
            } else {
                Object bk = j.bk(j.ak(cu.getClassName()), new Object[0]);
                if (bk == null) {
                    return;
                }
                for (Map.Entry entry : hashMap.entrySet()) {
                    j.ab(bk, cu.getMethodName(), new Object[]{entry.getKey(), entry.getValue()});
                }
                Object aa = j.aa(bk, cv.getMethodName());
                if (aa == null || (ab = j.ab(ab, cr.getMethodName(), new Object[]{str3, aa})) == null) {
                    return;
                }
            }
        } else if (str3.equals("GET") && (ab = j.ab(ab, cr.getMethodName(), new Object[]{"GET", null})) == null) {
            return;
        }
        Object aa2 = j.aa(ab, cw.getMethodName());
        if (aa2 == null) {
            return;
        }
        JsonHookStatic jsonHookStatic = y.by;
        String str4 = "newCall";
        if (jsonHookStatic.getSoul().getCallFactory() == null) {
            ab2 = j.ab(j.ad(j.ak(jsonHookStatic.getSoul().getCallFactoryMethodData().getClassName()), jsonHookStatic.getSoul().getCallFactoryMethodData().getMethodName(), new Object[0]), "newCall", new Object[]{"okhttp3_builder_Build"});
        } else {
            Object callFactory = jsonHookStatic.getSoul().getCallFactory();
            if (jsonHookStatic.isLogin() && jsonHookStatic.getUserInfo().getLevel() >= 5) {
                str4 = y.cj("newCall");
            }
            ab2 = j.ab(callFactory, str4, new Object[]{aa2});
        }
        this.db = ab2;
    }

    public final String df(Object obj) {
        String e = b.e("okhttp3ResponseBodyMethodData");
        if (TextUtils.isEmpty(e)) {
            if (cx == null) {
                cx = c.n(ClassMatcher.create().usingStrings(new String[]{"Cannot buffer entire body for content length:", "source == null", "Content-Length (", "; charset=utf-8"}));
                cy = c.t(MethodMatcher.create().declaredClass(obj.getClass()).returnType(cx.getName()).paramCount(0));
            }
            MethodData methodData = cy;
            if (methodData != null) {
                e = methodData.getMethodName();
                b.g("okhttp3ResponseBodyMethodData", e);
            }
        }
        j.bi(new Object[]{"response", obj.getClass(), e});
        return e;
    }

    public final void dg(c cVar) {
        if (this.db != null) {
            new Thread((Runnable) new aa(0, this, cVar)).start();
        } else {
            j.bi(new Object[]{"Call 为空1"});
        }
    }

    public final String dh() {
        Object aa;
        Object obj = this.db;
        if (obj == null) {
            j.bi(new Object[]{"Call 为空3"});
            return null;
        }
        try {
            Object callMethod = XposedHelpers.callMethod(obj, "execute", new Object[0]);
            if (callMethod == null) {
                j.bi(new Object[]{"response is Null"});
                return null;
            }
            if (TextUtils.isEmpty(df(callMethod)) || (aa = j.aa(callMethod, df(callMethod))) == null) {
                return null;
            }
            return (String) j.aa(aa, "string");
        } catch (Exception e) {
            e.printStackTrace();
            return null;
        }
    }
}
